package cate.game.admin.menu.sim;

import cate.game.common.time.TimeResp;
import cp.solution.util.time.DateKit;
import cate.game.GameBody;
import cate.game.admin.menu.MenuSetup;

public class SimMenu extends MenuSetup {

    public SimMenu(GameBody game) {
        super("模拟");

        reg(
                game,
                "触发跨天事件",
                0,
                "与真实跨天有区别，不改变服务器时间",
                (role, params) -> {
                    logger.info("{}调用了模拟跨天操作", role.getBase().name);
                    game.onDaySpan();
                    game.role.onDaySpanForce();
                    game.notice.message(role, "触发跨天成功！");
                });

        reg(
                game,
                "触发跨周事件",
                0,
                "与真实跨周有区别，不改变服务器时间",
                (role, params) -> {
                    logger.info("{}调用了模拟跨周操作", role.getBase().name);
                    game.onWeekSpan();
                    game.role.onWeekSpanForce();
                    game.notice.message(role, "触发跨周成功！");
                });

        reg(
                game,
                "触发跨月事件",
                0,
                "与真实跨月有区别，并不改变服务器时间",
                (role, params) -> {
                    logger.info("{}调用了模拟跨月操作", role.getBase().name);
                    game.onMonthSpan();
                    game.role.onMonthSpanForce();
                    game.notice.message(role, "触发跨月成功！");
                });

        reg(game, "时间偏移", 5, "参数全为空，则将清空偏移。参数1:天 参数2:时 参数3:分 参数4:秒 参数5:战区编码(不填就是本服配置的战区)  【会给前端发TimeResp消息】", (role, params) -> {
            int days = toInt(params, 0, 0);
            int hours = toInt(params, 1, 0);
            int minutes = toInt(params, 2, 0);
            int seconds = toInt(params, 3, 0);
            boolean reset = (days == 0 && hours == 0 && minutes == 0 && seconds == 0);
            long offsetMs = 24l * 3600_000l * days + 3600_000l * hours + 60_000l * minutes + 1000l * seconds;
            StringBuilder report = new StringBuilder();
            if(reset) {
                game.time.resetOffset(0l);
            } else {
                game.time.addOffset(offsetMs);
            }
            report.append("游戏服时间:" + game.time.nowStr());
            report.append("\r\n哈哈哈");
            new TimeResp(game).sendNow(role);
            game.notice.message(role, report.toString());
        });

        reg(game, "读取时间偏移", 0, "【会给前端发TimeResp消息】", (role, params) -> {
            long v = game.status.data.timeOffset;
            new TimeResp(game).sendNow(role);
            game.notice.message(role, "时间偏移："+ DateKit.toDayHms(v) + ", 值=" + v);
        });

        reg(game, "读取服务器时间", 0, "参数1：战区编码(不填就是本服配置的战区)", (role, params) -> {
            StringBuilder report = new StringBuilder();
            report.append("游戏服时间:" + game.time.nowStr());
            report.append("\r\n嘿嘿嘿");
            game.notice.message(role, report.toString());
        });
    }
}
